import QtQuick 1.0
import "../../../common/lib/kdeadmouseutils-build-desktop"

FocusScope {
    property alias urlFlux : xmlModel.source
    id:mainSF
    focus: true
    width: mainRect.width
    height: mainRect.height
    function beforeDestroy(){
		console.log('beforeDestroy');
		localPlayer.killAll();
		console.log('beforeDestroy killed');
    }
    PlayerExt {
		id:localPlayer
	}
Rectangle {
id:mainRect
width: 800
height: 500
focus: true
color: "#3E6F6F"

    Component {
	id:delegate
	Column {
	      spacing: 20
	      width:lstV.width
	      height:lstV.height
	      smooth: true
	      Text {
		id: txtTitle
		wrapMode : Text.Wrap
		width:parent.width-50
		text: title // ??+ pubDate
		color: "white"
		font.pixelSize: 20
	      }
	      Image {
		smooth: true ; 
		fillMode: Image.PreserveAspectFit;
		width: parent.width;
		height: 300 ; 
		source:imageSrc 
	      }
	      Text {
		id: txtDet
		wrapMode : Text.Wrap
		width:parent.width-50
		text: description
		color: "white"
		font.pixelSize: 20
	      }
	      Keys.onReturnPressed : {
		console.log('l:'+link);
		var u = link+'?sortie=rss';
		//rot.angle=30;
		
		listLoader.focus=true;
		listLoader.loadList(u);
		event.accepted = true;
	      }
	  }
  }
  
  
    //ici la liste des podcasts...
    Rectangle {
	id:podRect
	width: 400
	height: parent.height-20
	anchors.right:parent.right
	anchors.verticalCenter : parent.verticalCenter
	color:'transparent'
	Loader {
	    id:listLoader
	    anchors.fill: parent
	    source: "delegateDetail.qml"
	    focus:true
	    function loadList(url){
	      item.urlRss=url;
	    }
	}
	Connections {
	    target: listLoader.item
	    onSelectPodcast : {
	      console.log('podcast selected:' + url);
	      localPlayer.startThis(url);
	    }
	}
	Keys.onLeftPressed : {
	  listLoader.loadList('');
	  lstV.focus=true;
	}
	
    }
    //fin liste des podcasts
    
    
    
  Rectangle {
    id:rectLv
    width: 700
    height: parent.height-20
    
    color:'transparent'
    transform: Rotation {
         id: rotId
         origin.x: 0
         //origin.y: flipable.height/2
         axis.x: 0; axis.y: 1; axis.z: 0     // set axis.y to 1 to rotate around y-axis
         angle: 0    // the default angle
    }
    
    ListView {
      id:lstV
      focus: true
      anchors.fill:parent
      spacing: 20
      model: XmlListModel {
		  id: xmlModel
		  source: "http://feeds.feedburner.com/Pluzz-Actusociete?format=xml"
		  query: "/rss/channel/item"
		  XmlRole { name: "title"; query: "title/string()" }
		  XmlRole { name: "pubDate"; query: "pubDate/string()" }
		  XmlRole { name: "description"; query: "description/string()" }
		  XmlRole { name: "imageSrc"; query: "image/string()" }
		  XmlRole { name: "link"; query: "link/string()" }
	      }
      delegate: delegate
    }
  }
   
    
    states: [
	 State {
             name: "podcast" ; when: listLoader.activeFocus
	     //AnchorChanges	{ target: homeItem; anchors.horizontalCenter : parent.horizontalCenter}
	     //PropertyChanges    { target:podRect;x:400}
	     PropertyChanges	{ target: rotId;angle: 45 }
	     //AnchorChanges	{ target: podRect; anchors.left : rectLv.right}
         },
	 
         State {
             name: '' ; when: rectLv.activeFocus
             PropertyChanges	{ target: rotId;angle: 0 }
	     /*AnchorChanges	{ target: homeItem; anchors.left : parent.right }
	     AnchorChanges	{ target: loadingListItem; anchors.left : parent.left }
	     PropertyChanges	{ target: playingListLoader;focus: true }*/
         } 
         
    ]
    transitions: Transition {
         NumberAnimation { target: rotId; property: "angle"; duration: 200 }
         //NumberAnimation { properties: "x"; duration: 200 }
    }
    
}
}